/**
 * @class common.base.preview
 * @extends common.base.object
 * 预览基类
 */
define(function (require) {
    var BaseObject = require('common/base/object'),
        Tpl = require('text!./templates/preview.html');

    return BaseObject.extend({
        defaults: {},
        /**
         * 构造函数
         * @param  {Object} params 配置参数，如:
         *          {
         *              wrap:$(''),
         *              data_id:0,
         *              data_type:'voice',
         *              data_content:"",
         *              drop:funnction(){
         *
         *              }
         *          }
         */          
        initialize: function (params) {
            var _this = this;
            params=this.parseParams(params);
            _this.params = _.defaults(params, _this.defaults);
            _this.params.type = _this.type;
            if (!_.isset(_this.params.drop)) {
                _this.params.drop = false;
            }
            this.show();
        },
        /**
         * 获取组件html
         */          
        toString: function () {
            return this.html
        },
        change: function (params) {
            var _this = this;
            _.extend(_this.params, params);
            _this.$('.content').html(_this.render(_this.tpl, _this.params));
        },
        /**
         * 显示组件
         */          
        show: function () {
            var _this = this;
            _this.params.html = _this.render(this.tpl, this.params);
            //console.log(_this.params);
            _this.html = _this.render(Tpl, _this.params);

            if (_this.params.wrap) {
                _this.params.wrap.html(_this.html);
                _this.$('.drop').click(function () {
                    if (_.isFunction(_this.params.drop)) {
                        _this.params.drop.apply(_this, []);
                    }
                    _this.hide();
                });
                _this.bindEvents();
            }
        },
        parseParams: function (params) {
            return params;
        },
        /**
         * 关闭组件
         */            
        hide: function () {
            $(this.el).remove();
        }
    });
});